<template>
  <div class="app">
    <van-nav-bar
      title="打赏"
      left-text=""
      left-arrow
      @click="backlink()"
    ></van-nav-bar>
    <div class="zhujiao_card">
      <div class="zhujiaoimg">
        <img v-lazy="zhujiaoinfo.photo" alt="" />
      </div>
      <div class="zhujiaoinfo">
        <div class="nickname">{{ zhujiaoinfo.nickname }}</div>
        <div class="description">
          {{ zhujiaoinfo.zhujiao_id }}号{{ zhujiaoinfo.level }}
        </div>
        <van-text-ellipsis
          rows="1"
          class="description"
          :content="'简介：' + zhujiaoinfo.introduction"
          expand-text="展开"
          collapse-text="收起"
        />
      </div>
    </div>
    <div class="dashang_card">
      <div class="title">教练辛苦了，打个赏吧</div>
      <div class="dashangdiv">
        <div
          v-for="(item, index) in rewards"
          :key="index"
          :class="{
            dashangcard1: selectedCard === index,
            dashangcard: selectedCard !== index,
          }"
          @click="selectCard(index)"
        >
          <icon-svg
            :icon-class="item.iconClass"
            icon-color="#304056"
            class="rewardicon"
          ></icon-svg>
          <span :style="{ 'font-size': item.fontSize }">{{ item.amount }}</span>
        </div>
      </div>
      <div>
        <van-button
          :disabled="selectedCard == null"
          type="primary"
          class="dashangbtn"
          @click="showdashang = true"
        >
          确认打赏
        </van-button>
      </div>
    </div>
    <van-dialog
      v-model:show="showdashang"
      title="打赏教练"
      show-cancel-button
      class="dashangdialog"
      @confirm="gotopay"
    >
      <div>
        <div class="line1">金额可填写1-200元的任意金额</div>
        <van-field v-model="zhujiaoinfo.dashangmoney" class="dashanginput" />
      </div>
    </van-dialog>
  </div>
</template>

<script>
import { showToast } from "vant";
export default {
  data() {
    return {
      showdashang: false,
      zhujiaoinfo: {},
      selectedCard: null,
      rewards: [
        { iconClass: "zhujiao_reward_xuegao", amount: "￥2", fontSize: "18px" },
        { iconClass: "zhujiao_reward_drink", amount: "￥2", fontSize: "18px" },
        {
          iconClass: "zhujiao_reward_gaodian",
          amount: "￥2",
          fontSize: "18px",
        },
        {
          iconClass: "zhujiao_reward_hongbao",
          amount: "其他金额",
          fontSize: "14px",
        },
      ],
    };
  },
  methods: {
    backlink() {
      this.$router.back();
    },
    selectCard(index) {
      this.selectedCard = index;
      console.log(index)
      if (index != 3) {
        this.zhujiaoinfo.dashangmoney = 2;
      }else{
        this.zhujiaoinfo.dashangmoney = 0;
      }
    },
    gotopay() {
      if (
        this.zhujiaoinfo.dashangmoney > 0 &&
        this.zhujiaoinfo.dashangmoney <= 200
      ) {
        this.$router.push({
          name: "ZhujiaoRewardPay",
          params: {
            zhujiaoinfo: JSON.stringify(this.zhujiaoinfo),
          },
        });
      } else {
        showToast("打赏金额不在范围内");
      }
    },
  },
  created() {
    this.zhujiaoinfo = JSON.parse(this.$route.params.zhujiaoinfo);
    this.zhujiaoinfo.dashangmoney = 0;
  },
};
</script>

<style scoped>
.app {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100vh;
  background-color: #f2f3f5;
}
.zhujiao_card {
  width: 90%;
  margin: 10px auto;
  background-color: white;
  border-radius: 5px;
  box-sizing: border-box;
  padding: 10px;
  display: flex;
}
.zhujiaoimg {
  width: 70px;
  height: 70px;
  overflow: hidden;
  border-radius: 50%;
}
.zhujiaoimg img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.zhujiaoinfo {
  flex-grow: 1;
  margin-left: 5px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.nickname {
  font-size: 18px;
}
.description {
  max-width: calc(100vw - 150px);
  font-size: 16px;
  word-break: break-all;
}
.dashang_card {
  width: 90%;
  margin: 10px auto;
  background-color: white;
  border-radius: 5px;
  box-sizing: border-box;
  padding: 10px;
}
.dashang_card .title {
  font-size: 18px;
}
.dashangdiv {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
}
.dashangcard {
  width: 22%;
  height: 100px;
  box-sizing: border-box;
  padding: 8px;
  background-color: #f2f3f5;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  border-radius: 5px;
}
.dashangcard1 {
  width: 22%;
  height: 100px;
  box-sizing: border-box;
  padding: 7px;
  background-color: white;
  border: 1px solid #79a5fb;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  border-radius: 5px;
}
.rewardicon {
  width: 45px;
  height: 45px;
}
.dashangbtn {
  width: 100%;
}
.line1 {
  font-size: 14px;
  color: gray;
  margin-top: 5px;
}
</style>

<style>
.dashangdialog {
  padding: 10px !important;
}
.dashangdialog .van-dialog__header {
  text-align: start;
}
.dashangdialog .van-dialog__header {
  padding-top: 0 !important;
}
.dashanginput {
  margin: 5px auto;
  background-color: #f2f3f5 !important;
}
.dashanginput .van-field__value .van-field__body .van-field__control {
  text-align: center !important;
  height: 50px;
  font-size: 18px;
}
</style>